#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[200005];
bool color[200005];
ll calc(int n){
    ll ret=0;
    for(int i=1;i<=n;i++){
        bool have=false;
        int k;
        for(int j=i-1;j>=1;j--){
            if(color[j]==color[i]){
                have=true;
                k=j;
                break;
            }
        }
        if(have){
            if(a[k]==a[i]) ret+=a[i];
        }
    }
    return ret;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        ll ans=-1;
        scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        int U=(1<<n)-1;
        for(int i=0;i<=U;i++){
            int m=i;
            for(int j=1;j<=n;j++){
                color[j]=m%2;
                m/=2;
            }
            ans=max(ans,calc(n));
        }
        printf("%lld\n",ans);
    }
    return 0;
}
